<script type="text/javascript" >
    stFacebookToolbox.load_tooltip();
    stFacebookToolbox.on_submitform('#settingForm');
    jQuery("a[rel^='prettyPhoto']").prettyPhoto();
    stFacebookToolbox.pagingCallbackFunction = function(data){
        data['term'] = jQuery('#term').val();
        data['type'] = jQuery('#type').val();
        data['flag'] = jQuery('#flag').val();
    };
    stFacebookToolboxcustom.sortColumn('flagtypeid')
</script>
<div class="w100p bgl">
    <div class="w100p bgr p5b">
                <ul class="menu_right">
                      <li>
                          <a href="javascript:void(0);" onclick="stFacebookToolboxcustom.loadPage('search_analytics');" id="search_analytics">Search analytics</a>
                    </li>
                    <li class="current">
                          <a href="javascript:void(0);" onclick="stFacebookToolboxcustom.loadPage('search_results');" id="search_results">Search results</a>
                    </li>
                </ul>
                    <h2 class="red_color" style="padding-left:15px;">Search results
            </h2>
            <p align="center">
            Filter by term: <select id="term" onchange="stFacebookToolbox.loadPage('search_results&term='+jQuery('#term').val()+'&type='+jQuery('#type').val()+'&flag='+jQuery('#flag').val());" >
            <option value="0">All</option>
            <?php foreach($term as $row):?>
            <option value="<?php echo $row->searchtermid;?>" <?php if($dterm == $row->searchtermid){echo 'selected="true"';}?>><?php echo $row->searchterm;?></option>
            <?php endforeach;?>
            </select>
            by type: <select id="type" onchange="stFacebookToolbox.loadPage('search_results&term='+jQuery('#term').val()+'&type='+jQuery('#type').val()+'&flag='+jQuery('#flag').val());">
            <option value="0">All</option>
            <?php foreach($type as $row):?>
            <option value="<?php echo $row->messagetypeid;?>" <?php if($dtype == $row->messagetypeid){echo 'selected="true"';}?>><?php echo $row->messagetypeid;?></option>
            <?php endforeach;?>
            </select>
            by flag: <select id="flag" onchange="stFacebookToolbox.loadPage('search_results&term='+jQuery('#term').val()+'&type='+jQuery('#type').val()+'&flag='+jQuery('#flag').val());">
            <option value="0">All</option>
            <?php foreach($flag as $row):?>
            <option value="<?php echo $row->flagtypeid;?>" <?php if($dflag == $row->flagtypeid){echo 'selected="true"';}?> style="color:<?php echo $row->flagcolorcode;?>;"><?php echo $row->flagname;?></option>
            <?php endforeach;?>
            </select> Action on selected :<select onchange="stFacebookToolboxcustom.action(this.value)" id="delete" name="">
        <option value="select">Please select</option>
        <option value="delete">Delete selected messages</option>
        <option value="apply">Apply flag</option>
        <option value="remove">Remove flags</option>
        </select>
        <span id="flag_type_span" style="display:none;">
        flag type: <select id="flag_type" onchange='stFacebookToolbox.loadPage("search_results&apply_flag=true&id="+jQuery("#search_result_check").val()+"&flag_value="+this.value);'>
            <option value="0">Please select</option>
            <?php foreach($flag as $row):?>
            <option value="<?php echo $row->flagtypeid;?>" <?php if($dflag == $row->flagtypeid){echo 'selected="true"';}?> style="color:<?php echo $row->flagcolorcode;?>;"><?php echo $row->flagname;?></option>
            <?php endforeach;?>
            </select></span></p>
            
            
            <table class="widefat" cellspacing="0">
                <thead>
                    <tr>
                        <?php print_column_headers('stFacebookToolbox_stFacebookToolbox'); ?>
                    </tr>
                </thead>

                <tbody>
                <?php
                if (count($results) > 0) {
                    $tr_class = "";
                    $upload_data = wp_upload_dir();
                    foreach ($results as $result) {
                        $array[] = "'".$result->messageid."'";
                    	$id = explode("_",$result->messageid);
                    	$id = $id[0];
                         if( empty($tr_class) || $tr_class == "class='bg_gray2'"){
                            $tr_class = "class='bg_gray1'";
                        }else{
                            $tr_class = "class='bg_gray2'";
                        }
                        echo "<tr id='$result->messageid' $tr_class style='background-color:".$model->get_color($result->flagtypeid)."'>"
                        . "<td><a href='#inline_demo".$result->messageid."' rel='prettyPhoto' style='color:#000;'><img src='http://graph.facebook.com/" . $id. "/picture' /></a></td>"
                        . "<td><a href='#inline_demo".$result->messageid."' rel='prettyPhoto' style='color:#000;'>" . $result->messagetext
                         . "</a><div class=\"row-actions short_action\">"
                        . "<span class='edit' style='cursor:pointer;' onclick='window.open(\"http://facebook.com/".str_replace('_','/posts/',$result->messageid)."\");'>View on facebook</span>"
                        . "</div>" 
                        ."</td>"

                         . "<td><a href='#inline_demo".$result->messageid."' rel='prettyPhoto' style='color:#000;'>" . $model->get_user_model($id) . "</a></td>"
                         . "<td><a href='#inline_demo".$result->messageid."' rel='prettyPhoto' style='color:#000;'>" . $result->messagetypeid . "</a></td>"
                         . "<td><a href='#inline_demo".$result->messageid."' rel='prettyPhoto' style='color:#000;'>" . substr($result->createdtime,0,-3). "</a></td>"
                        . "<td><a href='#inline_demo".$result->messageid."' rel='prettyPhoto' style='color:#000;'>".$result->likes."</a></td>"
                        . "<td style='background-color:".$model->get_color($result->flagtypeid)."'><input type='checkbox' onclick='stFacebookToolboxcustom.search_result_check(\"".$result->messageid."\",this.checked);' id='checkbox_{$result->messageid}' style='margin-left:8px;'></td>"
                        . "</tr><tr style='display:none'><td>"
                        ;?>
                        <div id="inline_demo<?php echo $result->messageid;?>" style="display:none;">
                        <span style="color: red; font-weight: bold; font-size: 11pt;">Search result details</span>
						<p></p>
						<table border="0" cellpadding="0" cellspacing="5" align="center" width="100%">
						<tr>
							<td style="width:100px;" valign="top">
							Message id<span style="float:right;">:</span>
							</td>
							<td valign="top" style="padding-left:5px;">
								<?php echo $result->messageid;?>
							</td>
						</tr>
						<tr>
							<td valign="top">
							Search term<span style="float:right;">:</span>
							</td>
							<td valign="top" style="padding-left:5px;">
								<?php echo $model->get_term($result->searchtermid);?>
							</td>
						</tr>
						<tr>
							<td valign="top">
							User<span style="float:right;">:</span>
							</td>
							<td valign="top" style="padding-left:5px;">
								<a href="http://facebook.com/profile.php?id=<?php echo $id;?>" target="_blank"><?php echo $model->get_user_model($id);?></a>
							</td>
						</tr>
						<tr>
							<td valign="top">
							Message type<span style="float:right;">:</span>
							</td>
							<td valign="top" style="padding-left:5px;">
								<?php echo $result->messagetypeid;?>
							</td>
						</tr>
						<?php if($result->messagetext != ''){?>
						<tr>
							<td valign="top">
							Message text<span style="float:right;">:</span>
							</td>
							<td valign="top" style="padding-left:5px;">
								<?php echo $result->messagetext;?>
							</td>
						</tr>
						<?php } ?>
						<?php if($result->picture != ''){?>
						<tr>
							<td valign="top">
							Picture<span style="float:right;">:</span>
							</td>
							<td valign="top" style="padding-left:5px;">
								<img src="<?php echo $result->picture;?>" style="width:75px;" />
							</td>
						</tr>
						<?php } ?>
						<?php if($result->link != ''){?>
						<tr>
							<td valign="top">
							Link<span style="float:right;">:</span>
							</td>
							<td valign="top" style="padding-left:5px;">
								<?php echo $result->link;?>
							</td>
						</tr>
						<?php } ?>
						<?php if($result->source != ''){?>
						<tr>
							<td valign="top">
							Source<span style="float:right;">:</span>
							</td>
							<td valign="top" style="padding-left:5px;">
								<?php echo $result->source;?>
							</td>
						</tr>
						<?php } ?>
						<?php if($result->icon != ''){?>
						<tr>
							<td valign="top">
							Icon<span style="float:right;">:</span>
							</td>
							<td valign="top" style="padding-left:5px;">
								<img src="<?php echo $result->icon;?>" />
							</td>
						</tr>
						<?php } ?>
						<?php if($result->createdtime != ''){?>
						<tr>
							<td valign="top">
							Created time<span style="float:right;">:</span>
							</td>
							<td valign="top" style="padding-left:5px;">
								<?php echo $result->createdtime;?>
							</td>
						</tr>
						<?php } ?>
						<?php if($result->updatedtime != ''){?>
						<tr>
							<td valign="top">
							Updated time<span style="float:right;">:</span>
							</td>
							<td valign="top" style="padding-left:5px;">
								<?php echo $result->updatedtime;?>
							</td>
						</tr>
						<?php } ?>
						<?php if($result->likes != ''){?>
						<tr>
							<td valign="top">
							Likes<span style="float:right;">:</span>
							</td>
							<td valign="top" style="padding-left:5px;">
								<?php echo $result->likes;?>
							</td>
						</tr>
						<?php } ?>
						</table>
						
						</div></td></tr>
                        <?php } 
                    
                }
                ?>
                </tbody>
            </table>
            <input type="hidden" id="search_result_check" />
            <input type="hidden" id="search_result_check_normal" value="<?php echo implode(',',$array);?>" />
            <div class="page_d">
                <?php echo $pagination?>
                <div class="cl"></div>
            </div>
</div>
    </div>